using System.Collections.Generic;
using Lockstep.Game;
using Lockstep.Logging;
using Lockstep.Math;
using Lockstep.Serialization;
using Lockstep.Util;
using NetMsg.Common;

namespace Lockstep.Game
{
    public class GameInputService : IInputService
    {
        public static PlayerInput CurGameInput = new PlayerInput();
        public void Execute(InputCmd cmd, object entity)
        {
            var input = new Deserializer(cmd.content).Parse<PlayerInput>();
            var playerInput = entity as PlayerInput;
            playerInput.inputUV = input.inputUV;
            playerInput.isInputFire = input.isInputFire;
            playerInput.inputUV2 = input.inputUV2;
            playerInput.isInputFire2 = input.isInputFire2;
        }

        public List<InputCmd> GetInputCmds()
        {
            if (CurGameInput.Equals(PlayerInput.Empty)) {
                return null;
            }
            return new List<InputCmd>() {
                new InputCmd() {
                    content = CurGameInput.ToBytes()
                },
            };
        }

        public List<InputCmd> GetDebugInputCmds()
        {
            return new List<InputCmd>() {
                new InputCmd() {
                    content = new PlayerInput() {
                        inputUV = new LVector2(LRandom.Range(-1,1),LRandom.Range(-1,1)),
                        isInputFire = LRandom.Range(0,1) == 1,
                    }.ToBytes()
                },
            };
        }
    }
}